<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('推荐药新增')" />
</head>
<body class="gray-bg">

<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            商品码：<input type="text" name="goodscode" th:placeholder="商品码"/>
                        </li>
                        <!-- <li>
                             拼音码：<input type="text" name="plucode" th:placeholder="条码"/>
                         </li>-->
                        <li>
                            商品名称：<input type="text" name="goodsname" th:placeholder="商品名称"/>
                        </li>

                        <li>
                            药品类型：<select name="classname"  id="deviceType">
                            <option value="">---请选择---</option>
                            <option value="OTC呼吸系统">OTC呼吸系统</option>

                            <option value="OTC解热镇痛">OTC解热镇痛</option>

                            <option value="OTC其他类">OTC其他类</option>
                            <option value="OTC其他类（内）">OTC其他类（内）</option>
                            <option value="OTC清热解毒">OTC清热解毒</option>
                            <option value="OTC外用（串味）">OTC外用（串味）</option>
                            <option value="OTC外用药">OTC外用药</option>
                            <option value="OTC五官科">OTC五官科</option>
                            <option value="OTC消化系统">OTC消化系统</option>
                            <option value="参茸">参茸</option>
                            <option value="处方药">处方药</option>
                            <option value="含麻黄碱专柜">含麻黄碱专柜</option>
                            <option value="呼吸系统">呼吸系统</option>
                            <option value="解热镇痛">解热镇痛</option>
                            <option value="九珍堂">九珍堂</option>
                            <option value="日用百货">日用百货</option>
                            <option value="上虹">上虹</option>
                            <option value="食品">食品</option>
                            <option value="外用药">外用药</option>
                            <option value="维生素">维生素</option>
                            <option value="消化系统">消化系统</option>
                            <option value="心血管">心血管</option>
                            <option value="医疗器械">医疗器械</option>
                            <option value="原研药">原研药</option>

                        </select>
                        </li>

                        <!--                         suw 20210204  value 从1 改为 '' 不去除 维护表中已经存在数据-->
                        <li hidden>
                            <input id="flag3" name="flag3" value=""></input>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search('post-form','bootstrap-table-goods')"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>

                        </li>
                    </ul>
                </div>
            </form>
        </div>


        <div class="col-sm-6" >
            <div class="btn-group-sm"  id="toolbar-goods" role="group">
                <a class="btn btn-success" onclick="selectRemove()" >
                    <i class="fa"></i> 移出推广
                </a>
                <a class="btn btn-success" onclick="selectCommit()" >
                    <i class="fa"></i> 应用到选定
                </a>
            </div>
            <div class=" select-table table-striped col-sm-12" >
                <table id="bootstrap-table-goods"></table>
            </div>
        </div>
        <div class="col-sm-6" >

            <div class="col-sm-12 select-table table-striped" >
                <div class="btn-group-sm" id="toolbar-jd" role="group">
                    <h3 >
                        分类设置
                    </h3>
                </div>
                <table id="bootstrap-table"></table>
            </div>
            <div class="col-sm-12 select-table table-striped" >
                <div class="btn-group-sm" id="toolbar" role="group">
                    <h3 >
                        新增商品
                    </h3>
                </div>
                <table id="bootstrap-table-file"></table>
            </div>
        </div>




    </div>

</div>
</div>


<th:block th:include="include :: footer" />
<script th:inline="javascript">

    //  var editFlag = [[${@permission.hasPermi('system:post:edit')}]];
    // var removeFlag = [[${@permission.hasPermi('system:post:remove')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "baodao/demo02";
    var prefix2 = ctx + "baodao/linktemplate";

    var ids = new Array();
    ids = [0];

    $(function() {

        //$('#link-template-table').bootstrapTable('refresh');
        var options_goods = {
            id: "bootstrap-table-goods",
            toolbar:"toolbar-goods",
            url: ctx+ "jd" + "/queryGoodsInfoForJD",
            //createUrl: prefix + "/add/{id}",
            //updateUrl: prefix + "/edit/{id}",
            //removeUrl: prefix + "/remove",
            //exportUrl: prefix + "/export",
            height: $(window).height() + 80,
            /*  sortName: "companyId",*/
            modalName: "药品关系",
            rememberSelected: true,
            columns: [{
                checkbox: true
            },
                {
                    field: 'goodscode',
                    title: '商品码'
                },
                {
                    field: 'goodsname',
                    title: '商品名称'
                },
                {
                    field: 'norm',
                    title: '规格'
                },
                {
                    field: 'cnt',
                    title: '数量',
                    align: "right",
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        /* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');*/
                           actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="queryJDTJGoods(\'' + row.goodscode + '\')"><i class="fa fa-edit"></i>详情</a> ');
                        /* actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        /* actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        return actions.join('');
                    }
                }
            ],


        };
        $.table.init(options_goods);

        var options_jd = {
            id: "bootstrap-table",
            url : ctx + "jd/queryGoodsByGoodsCodes",
            toolbar:"toolbar-jd",
            //removeUrl: prefix + "/delete/{id}",
            modalName: "京东推荐商品明细",
            // 测试新增 查询条件
            queryParams: function(params) {
                var curParams = {
                    // 传递参数查询参数
                    pageSize: params.limit,
                    pageNum: params.offset / params.limit + 1,
                    searchValue: params.search,
                    orderByColumn: params.sort,
                    isAsc: params.order,

                    ids: ids.join(',')
                }
                return curParams;
            },
            height: $(window).height()/2 + 100,
            columns: [
                /*{
                    field: '',
                    title: '序号',
                    // sortable: true,
                    //  align: "center",
                    width: 60,
                    formatter: function (value, row, index) {
                        return index + 1;
                    }
                },*/
                {
                    field: 'id',
                    title: '序号',
                    width: 50,
                },
                {
                    field: 'jdtj_id',
                    title: '商品编号',
                    width: 50,
                    visible: false
                },
                {
                    field: 'goodsName',
                    title: '商品名称',
                    width: 200,
                },
                {
                    field: 'goodsPicUrl',
                    title: '商品图片',
                    detailView : true,
                    visible :false,
                    width: 120,
                    formatter: function (value) {
                        let url = 'http://' + value;
                        console.log(url);
                        return '<img loading="lazy" src="'+ url +'" alt="Smiley face" width="100" height="100">'
                    }
                },
                {
                    field: 'goodsPrice',
                    title: '单价',
                    align: "right",
                    width: 50,

                },
                {
                    field: 'commission',
                    title: '佣金',
                    align: "right",
                    width: 50,
                },

                {
                    title: '操作',
                    align: 'center',
                    width: 100,
                    formatter: function(value, row, index) {
                        var actions = [];
                        /* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');row.sellNo + row.startTime + row.endTime*/
                        actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="jdReferralLink(\'' + row.referralLink +"','"+ row.createTime+ "','"+ row.goodsNum+ '\')"><i class="fa fa-edit"></i>京东</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="jdRemove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        /* actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.postId + '\')"><i class="fa fa-remove"></i>删除</a>');*/
                        // actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        //actions.push('<a class="btn btn-danger btn-xs ' + "removeFlag" + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.goodscode + '\')"><i class="fa fa-remove"></i>删除</a>');
                        return actions.join('');
                    }
                },


            ]
        };
        $.table.init(options_jd);

        var options = {
            id: "bootstrap-table-file",
            url: ctx + "jd/file/list",
            toolbar:"toolbar",
            //createUrl: prefix + "/add/{id}",
            //updateUrl: prefix + "/edit/{id}",
            //removeUrl: prefix + "/remove",

            height: $(window).height()/2 ,
            /*  sortName: "companyId",*/
            modalName: "京东推荐",
            // 测试父子表
            detailView: false,
            clickEdit:true,
            //onEditableSave: onEditableSave,
            //onLoadSuccess: initSwitch(),
            columns: [{
                checkbox: true
            },
                {
                    field:'createTime',
                    title: '日期',
                },
                {
                    field: 'fileName',
                    title: '文件名',
                    //width:100
                },
                {
                    field: 'goodsNum',
                    title: '商品数量',
                    align: "right",
                    width:50
                },
                {
                    title: '操作',
                    align: 'center',
                    /* width: 100,*/
                    formatter: function(value, row, index) {
                        var actions = [];
                        /* actions.push('<a class="btn btn-info  btn-xs ' + addFlag + '" href="javascript:void(0)" onclick="$.operate.add(\'' + row.goodscode + '\')"><i class="fa fa-plus"></i>新增</a> ');row.sellNo + row.startTime + row.endTime*/
                        actions.push('<a class="btn btn-success btn-xs ' + "editFlag" + '" href="javascript:void(0)" onclick="queryJDTJDetails(\'' + row.fileName +"','"+ row.createTime+ "','"+ row.goodsNum+ '\')"><i class="fa fa-edit"></i>选取</a> ');
                        return actions.join('');
                    }
                },



            ],
        };
        $.table.init(options);

    });
</script>

<script>
    function queryJDTJGoods(p1){
        var url = ctx + "jd/goods/goodsDetails/"  + p1+"";
        console.log("跳转页面： " + url)
        console.log("请求连接： " + url)
        $.modal.open('京东推荐商品详情',url,1200,800);

        /*$.ajax({
            type: 'post',
            url: ctx + 'jd/goodsCode',
            timeout: 30000,
            //	data : queryParams,
            data: {"goodsCode":p1},
            dataType: 'json',
            success: function (data) {
                console.log(data);
                if(data.code == 0) {
                    alert("成功")
                }else{
                    alert("失败")
                }

            },
            error: function () {
                alert("调用数据接口失败,请联系管理员");
            }
        });*/
    }

    function queryJDTJDetails(p1,p2,p3) {
        console.log("查询小票明细： " + p1);
        if (p1 == null)
            //alert("小票号为空")
            // {
        {
            $.modal.alertWarning('小票号为空');
        }
        else {
            // p1 = "dkjfaldskfladskfjlas";
            console.log("弹窗展示交易明细")


            var classCode = $('#classcode').val();


            //var url = prefix +"/JDTJDetails/"  + p1;
            var url = ctx + "jd/global" +"/globalDetails/"  + p1+"?type=3&classCode="+classCode ;
            console.log("跳转页面： " + url)
            console.log("请求连接： " + url)
            $.modal.open('京东推荐商品',url,1200,800);
        }
    }

    function jdRemove(p1) {

        ids.remove(p1);
        $('#bootstrap-table').bootstrapTable('refresh');
    }

    function  jdReferralLink(p1,p2,p3){
        console.log('京东推广链接：' + p1);
        window.open(p1)
        //window.parent.$('#bootstrap-table').bootstrapTable('refresh');
    }

    // 数组移出方法
    Array.prototype.remove = function(val) {
        var index = this.indexOf(val);
        if (index > -1) {
            this.splice(index, 1);
        }
    };
</script>

<script>


    function selectRemove() {
        // $.table.set();
        var rows = $("#bootstrap-table-goods").bootstrapTable('getSelections');
        //var rows = $.common.isEmpty($("#bootstrap-table-goods").options.uniqueId) ? $("#bootstrap-table-goods").selectFirstColumns() : $("#bootstrap-table-goods").selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        console.log("已选择数据数量：" + rows.length)
        //console.log("已选择数据" + rows.toString())
        //let id = rows.toString();
        var arrs = new Array();
        for (var i=0;i<rows.length;i++){
            arrs.push(rows[i].goodscode);
        }
        console.log(arrs);


        var jdrow  = $("#bootstrap-table").bootstrapTable('getData');
        console.log(jdrow);
        var arrs2 = new Array();
        for( i=0;i<jdrow.length;i++) {
            arrs2.push(jdrow[i].id);

        }
        console.log(arrs2);


        $.ajax({
            type: 'post',
            url: ctx + 'jd/removeJDTJByGoodsCodes',  // 获取设备历史温度
            timeout: 30000,
            data: {"key1": arrs},
            traditional:true,
            dataType: 'json',
            success: function (data) {

                console.log(data);
                alert("操作成功");
                $('#bootstrap-table-goods').bootstrapTable('refresh');
                $('#bootstrap-table').bootstrapTable('refresh');
            },

            error: function () {
                alert("调用数据接口失败");
            }
        });


    }


    function selectCommit(){
        //var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        //var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        var rows = $("#bootstrap-table-goods").bootstrapTable('getSelections');
        //var rows = $.common.isEmpty($("#bootstrap-table-goods").options.uniqueId) ? $("#bootstrap-table-goods").selectFirstColumns() : $("#bootstrap-table-goods").selectColumns(table.options.uniqueId);
        if (rows.length == 0) {
            $.modal.alertWarning("请至少选择一条记录");
            return;
        }
        console.log("已选择数据数量：" + rows.length)
        //console.log("已选择数据" + rows.toString())
        //let id = rows.toString();
        var arrs = new Array();
        for (var i=0;i<rows.length;i++){
            arrs.push(rows[i].goodscode);
        }
        console.log(arrs);

        var jdrow  = $("#bootstrap-table").bootstrapTable('getData');
        console.log(jdrow);

        var arrs2 = new Array();
        for( i=0;i<jdrow.length;i++) {
            arrs2.push(jdrow[i].id);

        }

        if (arrs2.length == 0) {
            $.modal.alertWarning("请至少选择一条推荐记录");
            return;
        }
        console.log(arrs2);

        $.ajax({
            type: 'post',
            url: ctx + 'jd/saveGoodsByGoodsCodes',  // 获取设备历史温度
            timeout: 30000,
            data: {"key1": arrs,"key2": arrs2},
            traditional:true,
            dataType: 'json',
            success: function (data) {

                console.log(data);
                alert("操作成功");
                $('#bootstrap-table-goods').bootstrapTable('refresh');
                $('#bootstrap-table').bootstrapTable('refresh');
            },

            error: function () {
                alert("调用数据接口失败");
            }
        });

    }

    function refreshLinkTemplate() {
        $('#link-template-table').bootstrapTable('refresh');
    }




</script>

</body>
</html>
